/*
 * Currency.java
 *
 * Created on April 14, 2007, 4:21 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ge.info.domain.currency;

import ge.ktapestry.propertyselections.IComboItem;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Date;

/**
 *
 * @author Administrator
 */
public class Currency implements Serializable, IComboItem
{
    
    private static final int serviceID = 23;
    
    private int currencyID;
    private int countryID;
    private String abbrev;
    private String curName;
    private int unit = 1;
    private double rate;
    private double mrate;
    private double smrate;
    private Date cdate;

    public Currency()
    {
    }
    
    public boolean equals(Object o)
    {
        if (!(o instanceof Currency))
        {
            return false;
        }
        return this.getCurrencyID() == (((Currency) o).getCurrencyID());
    }
    public String getUniqueID()
    {
        return String.valueOf(currencyID);
    }
    
    public String getDisplayName()
    {
        return curName;
    }
    


    public  String convertTo(Currency currency)
    {
        if (rate < 0.0001 && rate > -0.0001 )
        {
            return "-";
        }
        DecimalFormat formatter = new DecimalFormat("#0.0000");
        return formatter.format(currency.getRate() * unit / rate / currency.getUnit());
    }

    public  String convertMTo(Currency currency)
    {
        if (mrate < 0.0001 && mrate > -0.0001 )
        {
            return "-";
        }
        DecimalFormat formatter = new DecimalFormat("#0.0000");
        return formatter.format(currency.getMrate() * unit / mrate / currency.getUnit());
    }

        public  String convertSmTo(Currency currency)
    {
        if (smrate < 0.0001 && smrate > -0.0001 )
        {
            return "-";
        }
        DecimalFormat formatter = new DecimalFormat("#0.0000");
        return formatter.format(currency.getSmrate() * unit / smrate / currency.getUnit());
    }

    public  String convertAmountTo(Currency currency, Integer amount)
    {
        if (amount == null)
        {
            return "";
        }
        if (rate < 0.0001 && rate > -0.0001 )
        {
            return "-";
        }
        DecimalFormat formatter = new DecimalFormat("#0.0000");
        return formatter.format(amount * currency.getRate() * unit / rate / currency.getUnit());
    //
    }

    public  String convertAmountMTo(Currency currency, Integer amount)
    {
        if (amount == null)
        {
            return "";
        }
        if (mrate < 0.0001 && mrate > -0.0001 )
        {
            return "-";
        }
        DecimalFormat formatter = new DecimalFormat("#0.0000");
        return formatter.format(amount * currency.getMrate() * unit  / mrate / currency.getUnit());
    }

    public  String convertAmountSmTo(Currency currency, Integer amount)
    {
        if (amount == null)
        {
            return "";
        }
        if (smrate < 0.0001 && smrate > -0.0001 )
        {
            return "-";
        }
        DecimalFormat formatter = new DecimalFormat("#0.0000");
        return formatter.format(amount * currency.getSmrate() * unit  / smrate / currency.getUnit());
    }

    public double getRate()
    {
        return rate;
    }
    public void setRate(double rate)
    {
        this.rate = rate;
    }

     public Date getCdate()
    {
        return cdate;
    }

    public void setCdate(Date cdate)
    {

        this.cdate = cdate;
    }

    public double getMrate()
    {
        return mrate;
    }
    public void setMrate(double mrate)
    {
        this.mrate = mrate;
    }

    public double getSmrate()
    {
        return smrate;
    }
    public void setSmrate(double smrate)
    {
        this.smrate = smrate;
    }

    public int getCurrencyID()
    {
        return currencyID;
    }
    
    public void setCurrencyID(int currencyID)
    {
        this.currencyID = currencyID;
    }
    
    public String getAbbrev()
    {
        return abbrev;
    }
    
    public void setAbbrev(String abbrev)
    {
        this.abbrev = abbrev;
    }
    
    public String getCurName()
    {
        return curName;
    }
    
    public void setCurName(String curName)
    {
        this.curName = curName;
    }
    
    public int getUnit()
    {
        return unit;
    }
    
    public void setUnit(int unit)
    {
        this.unit = unit;
    }
    
    public int getCountryID()
    {
        return countryID;
    }
    
    public void setCountryID(int countryID)
    {
        this.countryID = countryID;
    }
    
    public static int getServiceID()
    {
        return serviceID;
    }
}
